<%@ WebHandler Language="VB" Class="GetFastPageCount" %>
Imports System.Web
Imports System.IO
Imports System.Net
Imports System.Web.Configuration
Imports System.Web.SessionState
Public Class GetFastPageCount
Implements IHttpHandler
Implements IReadOnlySessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' Environmental Setup
PccConfig.LoadConfig("prizmconfig.xml")
Dim origDocument As String = context.Request.QueryString("fileName")
Dim document As String = PccCommon.getDownloadedName(origDocument)
Dim documentLocation As String = PccCommon.getDownloadedPath(origDocument)
Dim tempLocation As String = PccConfig.TempFolder
Dim originalDocument As String = System.IO.Path.Combine(documentLocation, document)
Dim pageContent As String = ""
If System.IO.File.Exists(originalDocument) Then
Dim UniqueFileIdHash As String = PccCommon.getFileHash(documentLocation & document)
Dim fastpgcntFile As String = System.IO.Path.Combine(tempLocation, UniqueFileIdHash & "_" & document & "_fastpagecount.txt")
If System.IO.File.Exists(fastpgcntFile) Then
Dim tr As TextReader = New StreamReader(fastpgcntFile)
pageContent = tr.ReadLine()
tr.Close()
End If
If (pageContent Is Nothing Or pageContent.Trim().Equals("") Or pageContent.Trim().Equals("0")) Then
Try
Dim HttpWReq As HttpWebRequest = DirectCast(WebRequest.Create(PccConfig.ImagingService + "/convert2swf?fastpgcnt&source=" & HttpUtility.UrlEncode(originalDocument)), HttpWebRequest)
HttpWReq.Timeout = 660000
Dim HttpWResp As HttpWebResponse = DirectCast(HttpWReq.GetResponse(), HttpWebResponse)
Dim sr As New StreamReader(HttpWResp.GetResponseStream(), System.Text.Encoding.UTF8)
pageContent = sr.ReadToEnd()
HttpWResp.Close()
sr.Close()
Dim tw As TextWriter = New StreamWriter(fastpgcntFile)
tw.Write(pageContent)
tw.Close()
Catch
pageContent = "1"
End Try
End If
context.Response.Write("pages=" & pageContent)
Else
context.Response.Status = "404 Not Found"
context.Response.StatusCode = 404
context.Response.Write("Error")
End If
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
|